home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14498 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: wmin.ac.uk!usenet
  2. From: Idoia Lertxundi <gsoec@wmin.ac.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Weird Linked Lists and malloc, a.s.a.p. please
  5. Date: 15 Apr 1996 12:10:32 GMT
  6. Organization: Westminster University
  7. Message-ID: <4ktebo$1t2@badger.wmin.ac.uk>
  8. NNTP-Posting-Host: ux213.wmin.ac.uk
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3_U1 sun4m)
  13. X-URL: news:comp.lang.c/154684-154784
  14.  
  15. Hi C sufferers/lovers,
  16.  
  17. I am working in the C program and I have come accross a weird prob.
  18. Rather than sending you code I will explain it in English as I have
  19. accurately located the problem.
  20.  
  21. I have a list which is being created dinamycally and a pointer pointing to
  22. the head of the list.
  23.  
  24. ptr=AllocateSpaceforptr();
  25. head=ptr;
  26.  
  27.  head  ptr....ptr
  28.  |   !   !  |
  29.  {}-{}-{}-NULL
  30.  
  31.   1  2  3  4
  32.  
  33. When I have put data in node number 3 I allocate with a malloc call
  34. node number 4 and as the function do not find suitable data to put
  35. in number 4 after a for loop I assign it to NULL. i.e.
  36.  
  37.      ptr=(FILEMODULE *)NULL;
  38.  
  39. When I do printfs I see that the list of ptr corresponds to what I was
  40. expecting the above picture when I print out the content of the head pointer
  41. list
  42. which points to the begining of the ptr list the result is unexpected.
  43. i.e.
  44.  
  45. head
  46.  |
  47.  {}-{}-{}-[not defined] the last node instead of being NULL is not defined.
  48.  
  49.  
  50.   1  2  3  4
  51.  
  52. By not defined,I mean that it is as it was left after "mallocking" and pointing
  53. to it, that is EMPTY.[] Although I put the NULL which shows perfectly well in
  54. the ptr
  55. list. Somehow the head list is not receiving the NULL asigment. WHY??
  56.  
  57. Any ideas you please mail me. I am sending this to a Newsgroup too.
  58.  
  59. Thank you.
  60.  
  61. P.S. The order is Read data to allocated, allocate a new one and traverse.
  62.  
  63. --
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. Ms Idoia Lertxundi                              .            ,
  66.                                                             .:/
  67. e-mail: gsoec@wmin.ac.uk                           .      ,,///;,   ,;/
  68. URL   : http://www.wmin.ac.uk/~gsoec/                .   o:::::::;;///
  69.                                                         >::::::::;;\\\
  70.                                                          `'\\\\\'" `;\
  71.                                                             `;\
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. "All philosophy," I told her, "is based on two things only:
  74.  curiosity and poor eyesight; if you had better eyesight you could see
  75.  perfectly well whether or not these stars are solar systems, and if
  76.  you were less curious you wouldn't care about knowing, which amounts
  77.  to the same thing. The trouble is, we want to know more than we can see."
  78.  
  79. Bernard de Fontanelle, Conversations on the Plurality of Worlds.
  80.  
  81.